<?php

declare(strict_types=1);

namespace App\Service;

use App\Model\SysUserLog as SysUserLogModel;

class SysLog extends BaseService
{
    // 日志列表
    public function logList(array $map, int $per_page = 10)
    {
        return SysUserLogModel::query()->with(['user:uid,username,real_name'])->where($map)->orderBy('id', 'desc')->paginate($per_page);
    }

    // 添加日志
    public function addLog($data)
    {
        $model = new SysUserLogModel();
        $model->uid = $data['uid'];
        $model->ip = $data['ip'];
        $model->host = $data['host'];
        $model->method = $data['method'];
        $model->url = $data['url'];
        $model->params = $data['params'];
        return $model->save();
    }
}
